{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 新闻事件数据\n",
    "\n",
    "新闻事件接口主要提供国内财经、证券、港股和期货方面的滚动新闻，以及个股的信息地雷数据。目前主要包括以下类别：\n",
    "\n",
    "    即时财经新闻\n",
    "    个股信息地雷\n",
    "    新浪股吧新闻\n",
    "\n",
    "即时新闻\n",
    "\n",
    "获取即时财经新闻，类型包括国内财经、证券、外汇、期货、港股和美股等新闻信息。数据更新较快，使用过程中可用定时任务来获取。\n",
    "\n",
    "参数说明：\n",
    "\n",
    "    top:int，显示最新消息的条数，默认为80条\n",
    "    show_content:boolean,是否显示新闻内容，默认False\n",
    "\n",
    "返回值说明：\n",
    "\n",
    "    classify :新闻类别\n",
    "    title :新闻标题\n",
    "    time :发布时间\n",
    "    url :新闻链接\n",
    "    content:新闻内容（在show_content为True的情况下出现）\n",
    "\n",
    "调用方法：\n",
    "```\n",
    "import tushare as ts\n",
    "\n",
    "ts.get_latest_news() #默认获取最近80条新闻数据，只提供新闻类型、链接和标题\n",
    "ts.get_latest_news(top=5,show_content=True) #显示最新5条新闻，并打印出新闻内容\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "import pprint as pp\n",
    "\n",
    "news = ts.get_latest_news()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>classify</th>\n",
       "      <th>title</th>\n",
       "      <th>time</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>国内财经</td>\n",
       "      <td>财政部发布会：副部长解读“财政政策要更加积极”</td>\n",
       "      <td>07-26 10:38</td>\n",
       "      <td>http://finance.sina.com.cn/china/gncj/2018-07-...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>外汇</td>\n",
       "      <td>兴业投资:非美报复性反弹 欧银决议或助欧元破位</td>\n",
       "      <td>07-26 10:37</td>\n",
       "      <td>http://finance.sina.com.cn/money/forex/forexfx...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>证券</td>\n",
       "      <td>刚泰再转让房地产公司 接盘侠今年接手华信又脱手</td>\n",
       "      <td>07-26 10:35</td>\n",
       "      <td>http://finance.sina.com.cn/stock/s/2018-07-26/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>国内财经</td>\n",
       "      <td>脸书在中国注册子公司申请为何被拒绝？外交部回应</td>\n",
       "      <td>07-26 10:35</td>\n",
       "      <td>http://finance.sina.com.cn/chanjing/gsnews/201...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>证券</td>\n",
       "      <td>A股遭246亿主力资金流出 低价股上演涨停潮</td>\n",
       "      <td>07-26 10:21</td>\n",
       "      <td>http://finance.sina.com.cn/stock/jsy/2018-07-2...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>证券</td>\n",
       "      <td>奥赛康药业：借壳大通燃气失败一月后又携手东方新星</td>\n",
       "      <td>07-26 10:18</td>\n",
       "      <td>http://finance.sina.com.cn/stock/s/2018-07-26/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>证券</td>\n",
       "      <td>A股进一步对外开放 这两类外国人也可以炒A股了</td>\n",
       "      <td>07-26 10:18</td>\n",
       "      <td>http://finance.sina.com.cn/stock/y/2018-07-26/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>证券</td>\n",
       "      <td>老艾侃股：消化获利盘 方能再反弹</td>\n",
       "      <td>07-26 10:15</td>\n",
       "      <td>http://finance.sina.com.cn/zl/stock/2018-07-26...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>外汇</td>\n",
       "      <td>牛汇:Facebook二季度营收不及预期 股价暴跌逾2…</td>\n",
       "      <td>07-26 10:13</td>\n",
       "      <td>http://finance.sina.com.cn/money/forex/forexfx...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>外汇</td>\n",
       "      <td>牛汇:美欧贸易关系缓和 特朗称双方关系进入新阶段</td>\n",
       "      <td>07-26 10:10</td>\n",
       "      <td>http://finance.sina.com.cn/money/forex/forexfx...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  classify                         title         time  \\\n",
       "0     国内财经       财政部发布会：副部长解读“财政政策要更加积极”  07-26 10:38   \n",
       "1       外汇       兴业投资:非美报复性反弹 欧银决议或助欧元破位  07-26 10:37   \n",
       "2       证券       刚泰再转让房地产公司 接盘侠今年接手华信又脱手  07-26 10:35   \n",
       "3     国内财经       脸书在中国注册子公司申请为何被拒绝？外交部回应  07-26 10:35   \n",
       "4       证券        A股遭246亿主力资金流出 低价股上演涨停潮  07-26 10:21   \n",
       "5       证券      奥赛康药业：借壳大通燃气失败一月后又携手东方新星  07-26 10:18   \n",
       "6       证券       A股进一步对外开放 这两类外国人也可以炒A股了  07-26 10:18   \n",
       "7       证券              老艾侃股：消化获利盘 方能再反弹  07-26 10:15   \n",
       "8       外汇  牛汇:Facebook二季度营收不及预期 股价暴跌逾2…  07-26 10:13   \n",
       "9       外汇      牛汇:美欧贸易关系缓和 特朗称双方关系进入新阶段  07-26 10:10   \n",
       "\n",
       "                                                 url  \n",
       "0  http://finance.sina.com.cn/china/gncj/2018-07-...  \n",
       "1  http://finance.sina.com.cn/money/forex/forexfx...  \n",
       "2  http://finance.sina.com.cn/stock/s/2018-07-26/...  \n",
       "3  http://finance.sina.com.cn/chanjing/gsnews/201...  \n",
       "4  http://finance.sina.com.cn/stock/jsy/2018-07-2...  \n",
       "5  http://finance.sina.com.cn/stock/s/2018-07-26/...  \n",
       "6  http://finance.sina.com.cn/stock/y/2018-07-26/...  \n",
       "7  http://finance.sina.com.cn/zl/stock/2018-07-26...  \n",
       "8  http://finance.sina.com.cn/money/forex/forexfx...  \n",
       "9  http://finance.sina.com.cn/money/forex/forexfx...  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 信息地雷\n",
    "\n",
    "获取个股信息地雷数据。\n",
    "\n",
    "参数说明：\n",
    "\n",
    "    code:股票代码\n",
    "    date:信息公布日期\n",
    "\n",
    "返回值说明：\n",
    "\n",
    "    title:信息标题\n",
    "    type:信息类型\n",
    "    date:公告日期\n",
    "    url:信息内容URL\n",
    "\n",
    "调用方法：\n",
    "```\n",
    "import tushare as ts\n",
    "\n",
    "ts.get_notices()\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "\n",
    "ts.get_notices()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 新浪股吧\n",
    "\n",
    "获取sina财经股吧首页的重点消息。股吧数据目前获取大概17条重点数据，可根据参数设置是否显示消息内容，默认情况是不显示。\n",
    "\n",
    "参数说明：\n",
    "\n",
    "    show_content:boolean,是否显示内容，默认False\n",
    "\n",
    "返回值说明：\n",
    "\n",
    "    title, 消息标题\n",
    "    content, 消息内容（show_content=True的情况下）\n",
    "    ptime, 发布时间\n",
    "    rcounts,阅读次数\n",
    "\n",
    "调用方法：\n",
    "```\n",
    "import tushare as ts\n",
    "\n",
    "ts.guba_sina()\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>ptime</th>\n",
       "      <th>rcounts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>把握市场的节奏很关键</td>\n",
       "      <td>今天06:01</td>\n",
       "      <td>11753.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>风电板块盘中表现亮眼</td>\n",
       "      <td>07月25日 10:51</td>\n",
       "      <td>40737.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>大盘回调或是上车的机会</td>\n",
       "      <td>今天06:23</td>\n",
       "      <td>17188.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>大盘反弹在路上</td>\n",
       "      <td>今天07:10</td>\n",
       "      <td>10328.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>周期股修整指数震荡  热点散乱陷入迷茫</td>\n",
       "      <td>今天08:09</td>\n",
       "      <td>8543.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>游资活跃 指数震荡</td>\n",
       "      <td>今天08:10</td>\n",
       "      <td>13983.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>目前回调是为上涨蓄势</td>\n",
       "      <td>今天08:39</td>\n",
       "      <td>14545.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>技术性修复引发调整需求 需盘中确认方向选择！</td>\n",
       "      <td>今天09:24</td>\n",
       "      <td>16500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>市场高位震荡 短线风险开始加大</td>\n",
       "      <td>今天09:20</td>\n",
       "      <td>16729.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>题材主升期热点开始扩散 今日防范情绪高潮的炸板。</td>\n",
       "      <td>今天09:16</td>\n",
       "      <td>16230.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Facebook概念股大涨 两股涨停</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>水井坊：盈利能力持续提升 下半年重拾高增长可期</td>\n",
       "      <td>07月25日 10:55</td>\n",
       "      <td>37071.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>早盘超跌板块网络游戏以:迅游科技等多股涨停</td>\n",
       "      <td>07月25日 09:47</td>\n",
       "      <td>32445.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>华润双鹤：自产原料药生产缬沙坦制剂 不受召回事件影响</td>\n",
       "      <td>07月25日 10:35</td>\n",
       "      <td>48619.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>海康威视半年度业绩会：海外业务增速稳定</td>\n",
       "      <td>07月25日 10:06</td>\n",
       "      <td>160826.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>量能是否持续仍是关键</td>\n",
       "      <td>07月24日 08:12</td>\n",
       "      <td>98409.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>昭衍新药：可对疫苗试验进行相关评价</td>\n",
       "      <td>07月25日 10:39</td>\n",
       "      <td>30394.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>光启技术：控股股东资信良好 质押风险可控</td>\n",
       "      <td>07月25日 10:38</td>\n",
       "      <td>196476.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         title         ptime   rcounts\n",
       "0                   把握市场的节奏很关键       今天06:01   11753.0\n",
       "1                   风电板块盘中表现亮眼  07月25日 10:51   40737.0\n",
       "2                  大盘回调或是上车的机会       今天06:23   17188.0\n",
       "3                      大盘反弹在路上       今天07:10   10328.0\n",
       "4          周期股修整指数震荡  热点散乱陷入迷茫       今天08:09    8543.0\n",
       "5                    游资活跃 指数震荡       今天08:10   13983.0\n",
       "6                   目前回调是为上涨蓄势       今天08:39   14545.0\n",
       "7       技术性修复引发调整需求 需盘中确认方向选择！       今天09:24   16500.0\n",
       "8              市场高位震荡 短线风险开始加大       今天09:20   16729.0\n",
       "9     题材主升期热点开始扩散 今日防范情绪高潮的炸板。       今天09:16   16230.0\n",
       "10          Facebook概念股大涨 两股涨停                     0.0\n",
       "11     水井坊：盈利能力持续提升 下半年重拾高增长可期  07月25日 10:55   37071.0\n",
       "12       早盘超跌板块网络游戏以:迅游科技等多股涨停  07月25日 09:47   32445.0\n",
       "13  华润双鹤：自产原料药生产缬沙坦制剂 不受召回事件影响  07月25日 10:35   48619.0\n",
       "14         海康威视半年度业绩会：海外业务增速稳定  07月25日 10:06  160826.0\n",
       "15                  量能是否持续仍是关键  07月24日 08:12   98409.0\n",
       "16           昭衍新药：可对疫苗试验进行相关评价  07月25日 10:39   30394.0\n",
       "17        光启技术：控股股东资信良好 质押风险可控  07月25日 10:38  196476.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tushare as ts\n",
    "\n",
    "ts.guba_sina()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#如果要查看内容，方法如下：\n",
    "df = ts.guba_sina(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(df[3]['content']) #第3条消息的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
